home *** CD-ROM | disk | FTP | other *** search
- Path: cdn_news.telecom.com.au!usenet
- From: Jeff PAton <jpaton@vitgexec.telecom.com.au>
- Newsgroups: comp.lang.c
- Subject: Re: Problem...Problem!
- Date: 31 Jan 1996 01:25:47 GMT
- Organization: Telstra
- Message-ID: <4emger$qs@cdn_news.telecom.com.au>
- References: <4el09q$6im@ratree.psu.ac.th>
- NNTP-Posting-Host: 144.136.190.172
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
-
- s3610165@maliwan.psu.ac.th (Sanon CHAOCHAIYAPORN) wrote:
- >Dear all
- > This is a iteration method program. It use to find three values,
- >a b and c. This program will finish when variables, t[], are less than or
- >equal an error value, ERR. But my program has not been runing. Please,
- >advice me...:~( Thanks for your attention.
- >
- >Source:
- [snip]
- >main()
- >{
- [snip]
-
- > {
- [snip]
- > for(i=0;i<NUM;i++)
- > t[i] = v[i] - e[i];
- > for(i=0;i<NUM;i++)
- > e[i] = v[i];
- > }while((t[0] <= ERR) && (t[1] <= ERR) && (t[2] <= ERR) && (t[3] <= ERR) &&
- > (t[4] <= ERR) && (t[5] <= ERR) && (t[6] <= ERR) && (t[7] <= ERR));
- [snip]
-
- Why do the while() tests use <= (less than or equal to) not >= ?? Your program
- probably finishes on the first time through - if one of t[] is > ERR then the
- while() test fails, so it finishes.
-
- Also, a style comment - why not express your terminating condition along the lines of
-
- for (i= 0; i < NUM; i++)
- ErrorExceeded = t[i] >= ERR;
- } while (ErrorExceeded);
-
- More compact and less prone to error if you change NUM!
-
- Also, is the use of 8 as a divisor linked to the #define NUM 8 - if so you should
- probably use "/ NUM" instead of "/ 8" - makes your intention clearer
-
-